package com.ruoyi.controller;


import com.ruoyi.dto.ChangeAlarmLevelDto;
import com.ruoyi.dto.FirstAlertDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@Api(tags = "初步预警分级模型算法")
@RequestMapping("/riskEvaluate")
@RestController
public class FirstAlertController {

    @ApiOperation("获取预警等级--1:一级预警;2:二级预警;3:三级预警;4:四级预警")
    @PostMapping("/getAlertLevel")
    public Map getAlertLevel(@RequestBody FirstAlertDto firstAlertDto) {
        Map map = new HashMap();
        map.put("number",firstAlertDto.getNumber());
        String bjdj =firstAlertDto.getBjdj();
        String fxdj =firstAlertDto.getFxdj();
        if("1".equals(bjdj)){
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("3".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }else if("2".equals(bjdj)){
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("3".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }else if("3".equals(bjdj)){
            if("1".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("2".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("3".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }else if("4".equals(bjdj)){
            if("1".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("2".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("3".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        return map;
    }


    @ApiOperation("更新报警等级")
    @PostMapping("/changeAlarmLevel")
    public Map changeAlarmLevel(@RequestBody ChangeAlarmLevelDto changeAlarmLevelDto) {
        Map map = new HashMap();
        map.put("number",changeAlarmLevelDto.getNumber());
        Integer threeDayAlarmNum =changeAlarmLevelDto.getThreeDayAlarmNum();
        Integer alarmTime =changeAlarmLevelDto.getAlarmTime();
        map.put("input",changeAlarmLevelDto);
        if((null != threeDayAlarmNum && threeDayAlarmNum>=2)||(null != alarmTime && alarmTime>=24))
        {
            map.put("alarmLevel","一级报警");
        }
        else
        {
            map.put("alarmLevel","维持原来报警状态");
        }

        return map;
    }

    @ApiOperation("一级报警生成规则")
    @PostMapping("/generateAlarmLevelOne")
    public Map generateAlarmLevelOne(@RequestBody ChangeAlarmLevelDto changeAlarmLevelDto) {
        Map map = new HashMap();
        map.put("number",changeAlarmLevelDto.getNumber());
        Integer threeDayAlarmNum =changeAlarmLevelDto.getThreeDayAlarmNum();
        Integer alarmTime =changeAlarmLevelDto.getAlarmTime();
        map.put("input",changeAlarmLevelDto);
        if((null != threeDayAlarmNum && threeDayAlarmNum>=2)||(null != alarmTime && alarmTime>=24))
        {
            map.put("alarmLevel","一级报警");
        }
        else
        {
            map.put("alarmLevel","维持原来报警状态");
        }

        return map;
    }

}
